home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / vulgus.c < prev    next >
C/C++ Source or Header  |  2000-05-04  |  7KB  |  280 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11.  
  12.  
  13.  
  14. unsigned char *vulgus_bgvideoram,*vulgus_bgcolorram;
  15. size_t vulgus_bgvideoram_size;
  16. unsigned char *vulgus_scrolllow,*vulgus_scrollhigh;
  17. unsigned char *vulgus_palette_bank;
  18. static unsigned char *dirtybuffer2;
  19. static struct osd_bitmap *tmpbitmap2;
  20.  
  21.  
  22.  
  23. /***************************************************************************
  24.  
  25.   Convert the color PROMs into a more useable format.
  26.  
  27. ***************************************************************************/
  28. void vulgus_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  29. {
  30.     int i;
  31.     #define TOTAL_COLORS(gfxn) (Machine->gfx[gfxn]->total_colors * Machine->gfx[gfxn]->color_granularity)
  32.     #define COLOR(gfxn,offs) (colortable[Machine->drv->gfxdecodeinfo[gfxn].color_codes_start + offs])
  33.  
  34.  
  35.     for (i = 0;i < Machine->drv->total_colors;i++)
  36.     {
  37.         int bit0,bit1,bit2,bit3;
  38.  
  39.  
  40.         bit0 = (color_prom[0] >> 0) & 0x01;
  41.         bit1 = (color_prom[0] >> 1) & 0x01;
  42.         bit2 = (color_prom[0] >> 2) & 0x01;
  43.         bit3 = (color_prom[0] >> 3) & 0x01;
  44.         *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  45.         bit0 = (color_prom[Machine->drv->total_colors] >> 0) & 0x01;
  46.         bit1 = (color_prom[Machine->drv->total_colors] >> 1) & 0x01;
  47.         bit2 = (color_prom[Machine->drv->total_colors] >> 2) & 0x01;
  48.         bit3 = (color_prom[Machine->drv->total_colors] >> 3) & 0x01;
  49.         *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  50.         bit0 = (color_prom[2*Machine->drv->total_colors] >> 0) & 0x01;
  51.         bit1 = (color_prom[2*Machine->drv->total_colors] >> 1) & 0x01;
  52.         bit2 = (color_prom[2*Machine->drv->total_colors] >> 2) & 0x01;
  53.         bit3 = (color_prom[2*Machine->drv->total_colors] >> 3) & 0x01;
  54.         *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  55.  
  56.         color_prom++;
  57.     }
  58.  
  59.     color_prom += 2*Machine->drv->total_colors;
  60.     /* color_prom now points to the beginning of the lookup table */
  61.  
  62.  
  63.     /* characters use colors 32-47 (?) */
  64.     for (i = 0;i < TOTAL_COLORS(0);i++)
  65.         COLOR(0,i) = *(color_prom++) + 32;
  66.  
  67.     /* sprites use colors 16-31 */
  68.     for (i = 0;i < TOTAL_COLORS(2);i++)
  69.     {
  70.         COLOR(2,i) = *(color_prom++) + 16;
  71.     }
  72.  
  73.     /* background tiles use colors 0-15, 64-79, 128-143, 192-207 in four banks */
  74.     for (i = 0;i < TOTAL_COLORS(1)/4;i++)
  75.     {
  76.         COLOR(1,i) = *color_prom;
  77.         COLOR(1,i+32*8) = *color_prom + 64;
  78.         COLOR(1,i+2*32*8) = *color_prom + 128;
  79.         COLOR(1,i+3*32*8) = *color_prom + 192;
  80.         color_prom++;
  81.     }
  82. }
  83.  
  84.  
  85.  
  86. /***************************************************************************
  87.  
  88.   Start the video hardware emulation.
  89.  
  90. ***************************************************************************/
  91. int vulgus_vh_start(void)
  92. {
  93.     if (generic_vh_start() != 0)
  94.         return 1;
  95.  
  96.     if ((dirtybuffer2 = malloc(vulgus_bgvideoram_size)) == 0)
  97.     {
  98.         generic_vh_stop();
  99.         return 1;
  100.     }
  101.     memset(dirtybuffer2,1,vulgus_bgvideoram_size);
  102.  
  103.     /* the background area is twice as tall and twice as large as the screen */
  104.     if ((tmpbitmap2 = osd_create_bitmap(2*Machine->drv->screen_width,2*Machine->drv->screen_height)) == 0)
  105.     {
  106.         free(dirtybuffer2);
  107.         generic_vh_stop();
  108.         return 1;
  109.     }
  110.  
  111.     return 0;
  112. }
  113.  
  114.  
  115.  
  116. /***************************************************************************
  117.  
  118.   Stop the video hardware emulation.
  119.  
  120. ***************************************************************************/
  121. void vulgus_vh_stop(void)
  122. {
  123.     osd_free_bitmap(tmpbitmap2);
  124.     free(dirtybuffer2);
  125.     generic_vh_stop();
  126. }
  127.  
  128.  
  129.  
  130. WRITE_HANDLER( vulgus_bgvideoram_w )
  131. {
  132.     if (vulgus_bgvideoram[offset] != data)
  133.     {
  134.         dirtybuffer2[offset] = 1;
  135.  
  136.         vulgus_bgvideoram[offset] = data;
  137.     }
  138. }
  139.  
  140.  
  141.  
  142. WRITE_HANDLER( vulgus_bgcolorram_w )
  143. {
  144.     if (vulgus_bgcolorram[offset] != data)
  145.     {
  146.         dirtybuffer2[offset] = 1;
  147.  
  148.         vulgus_bgcolorram[offset] = data;
  149.     }
  150. }
  151.  
  152.  
  153.  
  154. WRITE_HANDLER( vulgus_palette_bank_w )
  155. {
  156.     if (*vulgus_palette_bank != data)
  157.     {
  158.         memset(dirtybuffer2,1,vulgus_bgvideoram_size);
  159.         *vulgus_palette_bank = data;
  160.     }
  161. }
  162.  
  163.  
  164.  
  165. /***************************************************************************
  166.  
  167.   Draw the game screen in the given osd_bitmap.
  168.   Do NOT call osd_update_display() from this function, it will be called by
  169.   the main emulation engine.
  170.  
  171. ***************************************************************************/
  172. void vulgus_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  173. {
  174.     int offs;
  175.     int scrollx,scrolly;
  176.  
  177.  
  178.     scrolly = -(vulgus_scrolllow[0] + 256 * vulgus_scrollhigh[0]);
  179.     scrollx = -(vulgus_scrolllow[1] + 256 * vulgus_scrollhigh[1]);
  180.  
  181.     for (offs = vulgus_bgvideoram_size - 1;offs >= 0;offs--)
  182.     {
  183.         int sx,sy;
  184.  
  185.  
  186.         if (dirtybuffer2[offs])
  187.         {
  188. //            int minx,maxx,miny,maxy;
  189.  
  190.  
  191.             sx = (offs % 32);
  192.             sy = (offs / 32);
  193.  
  194.             /* between level Vulgus changes the palette bank every frame. Redrawing */
  195.             /* the whole background every time would slow the game to a crawl, so here */
  196.             /* we check and redraw only the visible tiles */
  197. /*
  198.             minx = (sx + scrollx) & 0x1ff;
  199.             maxx = (sx + 15 + scrollx) & 0x1ff;
  200.             if (minx > maxx) minx = maxx - 15;
  201.             miny = (sy + scrolly) & 0x1ff;
  202.             maxy = (sy + 15 + scrolly) & 0x1ff;
  203.             if (miny > maxy) miny = maxy - 15;
  204.  
  205.             if (minx + 15 >= Machine->drv->visible_area.min_x &&
  206.                     maxx - 15 <= Machine->drv->visible_area.max_x &&
  207.                     miny + 15 >= Machine->drv->visible_area.min_y &&
  208.                     maxy - 15 <= Machine->drv->visible_area.max_y)
  209. */
  210.             {
  211.                 dirtybuffer2[offs] = 0;
  212.  
  213.                 drawgfx(tmpbitmap2,Machine->gfx[1],
  214.                         vulgus_bgvideoram[offs] + 2 * (vulgus_bgcolorram[offs] & 0x80),
  215.                         (vulgus_bgcolorram[offs] & 0x1f) + 32 * *vulgus_palette_bank,
  216.                         vulgus_bgcolorram[offs] & 0x20,vulgus_bgcolorram[offs] & 0x40,
  217.                         16*sy,16*sx,
  218.                         0,TRANSPARENCY_NONE,0);
  219.             }
  220.         }
  221.     }
  222.  
  223.  
  224.     /* copy the background graphics */
  225.     copyscrollbitmap(bitmap,tmpbitmap2,1,&scrollx,1,&scrolly,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  226.  
  227.  
  228.     /* Draw the sprites. */
  229.     for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
  230.     {
  231.         int code,i,col,sx,sy;
  232.  
  233.  
  234.         code = spriteram[offs];
  235.         col = spriteram[offs + 1] & 0x0f;
  236.         sx = spriteram[offs + 3];
  237.         sy = spriteram[offs + 2];
  238.  
  239.         i = (spriteram[offs + 1] & 0xc0) >> 6;
  240.         if (i == 2) i = 3;
  241.  
  242.         do
  243.         {
  244.             drawgfx(bitmap,Machine->gfx[2],
  245.                     code + i,
  246.                     col,
  247.                     0, 0,
  248.                     sx, sy + 16 * i,
  249.                     &Machine->drv->visible_area,TRANSPARENCY_PEN,15);
  250.  
  251.             /* draw again with wraparound */
  252.             drawgfx(bitmap,Machine->gfx[2],
  253.                     code + i,
  254.                     col,
  255.                     0, 0,
  256.                     sx, sy + 16 * i - 256,
  257.                     &Machine->drv->visible_area,TRANSPARENCY_PEN,15);
  258.             i--;
  259.         } while (i >= 0);
  260.     }
  261.  
  262.  
  263.     /* draw the frontmost playfield. They are characters, but draw them as sprites */
  264.     for (offs = videoram_size - 1;offs >= 0;offs--)
  265.     {
  266.         int sx,sy;
  267.  
  268.  
  269.         sx = 8 * (offs % 32);
  270.         sy = 8 * (offs / 32);
  271.  
  272.         drawgfx(bitmap,Machine->gfx[0],
  273.                 videoram[offs] + 2 * (colorram[offs] & 0x80),
  274.                 colorram[offs] & 0x3f,
  275.                 0,0,
  276.                 sx,sy,
  277.                 &Machine->drv->visible_area,TRANSPARENCY_COLOR,47);
  278.     }
  279. }
  280.